2B11 2001/2 Programming Exercises 2


Final Deadline: Noon Friday 26th October 2001

 

Purpose: Learning to use JUnit for test-first programming.

Marking: All questions are binary marked.
To hand-in: Print out the code and documentation you have written, and a coursework coversheet. Read and fill in the cover sheet, sign it and attach it to the print-out. Submit to the departmental office. Work should also be submitted electronically (instructions will be sent at the deadline).
All printing should be done on the line printer (a4lp) - don't use up your laser printer quota!

NOTE: You must keep all marked work as it forms a record of your progress. At the end of the course you are required to re-submit all work.


Preliminary Activities

Read the local Using JUnit webpage (http://www.cs.ucl.ac.uk/staff/G.Roberts/2001/2b11/usingjunit.html) , and set up JUnit so that you can use it. Make sure you set CLASSPATH correctly.

Also visit the official JUnit web page at http://www.junit.org/. There is a considerable amount of information available from the site, including a number of articles about using JUnit. In particular look at:


Learning to use JUnit

Q1. To familiarise yourself with JUnit, develop a complete JUnit test class to test your List implementation class from exercises 1. Use the test class to make sure that your list class is complete and works correctly.

Q2. Develop JUnit test classes to test the FileInput and FileOutput classes from 1B11 (see the links from the 2B11 web page to get the source code of the classes). (There is at least one bug in one of the classes, and you may remember writing your own non-JUnit test classes in 1B11)


Test-First Programming

Q3. Use the test-first approach to write a class to represent a specific time using this specification:

(Note, this is not meant to be a clock, just a class to represent a particular time.)

Q4.  Use test-first programming to design and implement a program to meet the following specification:

"A program is required to maintain the membership details of a club. The name and contact details of each club member should be recorded, along with the date they first joined and the date of their annual membership renewal. It should be possible to output a complete membership list (sorted both alphabetically and by order of joining date), a list of members who need to renew their membership in a given month and a list of members who are overdue in renewing their membership. It should also be possible to add new members and remove old members, including those who fail to renew. The details of all ex-members should be retained in a separate list. For everyday use, it should be possible to search for members, based on their name, address or joining date."

Remember the snack bar from 1B11? This is similar kind of design and programming problem (and the code is still on the web).

Start by sorting out the requirements to determine exactly what you need to implement (use your imagination to interpret the needs of the "client"). Then do some object-oriented analysis to identify candidate classes (CRC method). Then go straight for the test-first approach, working through each of your requirements in turn. Keep things simple and only implement what is needed (but remember to follow sound object-oriented design techniques). Let the test-first approach guide your detailed design.